package com.maolong.server.handler;

import com.maolong.server.exception.BaseException;
import com.maolong.server.exception.FileFailException;
import com.maolong.pojo.fuction.result.Result;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;


/**
 * 异常处理类
 */

@RestControllerAdvice
public class MyExceptionHandler {

    /**
     * 捕获异常，并且基础基础BaseException
     * @param e
     * @return
     */
    @ExceptionHandler(BaseException.class)
    public Result handleException(BaseException e){

        return Result.error(e.getMessage());
    }

    /**
     * 捕获异常，并且基础基础DataAccessException
     * 数据库异常
     * @param e
     * @return
//     */
//    @ExceptionHandler(DataAccessException.class)
//    public Result handleException(DataAccessException e){
//        return Result.error(ExceptionMessage.INTERNAL_ERROR);
//    }

    @ExceptionHandler(FileFailException.class)
    public ResponseEntity<String> handleException(FileFailException e){
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e.getMessage());
    }
}
